namespace OracleInternal.ConnectionPool
{
	internal class RoundRobin
	{
		private object m_sync;

		private int m_mod;

		private int m_count;

		public RoundRobin()
		{
			m_mod = 1;
			m_count = 0;
			m_sync = new object();
		}

		public int NextValue()
		{
			lock (m_sync)
			{
				m_count++;
				if (m_count >= m_mod)
				{
					m_count = 0;
				}
				return m_count;
			}
		}

		public int NextValue(int val)
		{
			if (val != int.MaxValue)
			{
				return ++val % m_mod;
			}
			return 0;
		}

		public void SetMax(int exclusiveMax)
		{
			lock (m_sync)
			{
				if (m_mod > 0)
				{
					m_mod = exclusiveMax;
				}
				else
				{
					m_mod = 1;
				}
			}
		}
	}
}
